package com.aau.edu.design.clone;


import org.springframework.beans.BeanUtils;

public class CloneTest {
    public static void main(String[] args) throws CloneNotSupportedException {
        User user1 = new User("jack", 21, new Address("中国", "CN"));
        User cloneUser = new User();
//        User cloneUser = (User) user1.clone();//深copy
        BeanUtils.copyProperties(user1, cloneUser);
        System.out.println(cloneUser == user1);  // false
        System.out.println(user1.getAddress() == cloneUser.getAddress());  // true
        cloneUser.getAddress().setAddressName("日本");
        cloneUser.setAge(25);
        cloneUser.setName("zhangsan");
        cloneUser.getAddress().setAddressCode("JAPAN");
        System.out.println(cloneUser);
        System.out.println(user1);
    }
}
